import req from "./config"
import { Api } from "./config/Api"
import { IPromiseShell, ISuccessLogin } from "./type"
import qs from "qs"

export interface IUserItem {
  id: number;
  username: string;
  sex: number;
  phoneNum: string;
  email: string;
  birth: number;
  introduction: string;
  location: string;
  avator: string;
  creatTime?: any;
  updateTime: number;
}
export const getUserById = (id: number): IPromiseShell<IUserItem> => req.get(Api.user + id)
export const getUserList = (): IPromiseShell<IUserItem[]> => req.get(Api.userList)

export interface ILoginItem {
  username: string
  password: string
}

// 用户登录
export const userLogin = (item: ILoginItem): IPromiseShell<any> => req.post(Api.login, item)
export const userRegister = (info: ILoginItem) => req.post(Api.register, info)

//判断用户是否存在
export const hasUser = (username: string) => req.get(Api.hasUser + username)
